﻿using ExpenseSystem.Core.DataAddOn;
using ExpenseSystem.Fether;
using ExpenseSystem.Model;

namespace ExpenseSystem.Core.CustomerModules
{
    public class CustomerBaseManager: CustomerManager
    {
        CustomerFetcher fetcher = new CustomerFetcher();
        public override bool Delete(CustomerModel Customer, out string message)
        {
            if (Customer.Site != profile.SiteId)
            {
                message = "当前登录的组织与档案所在组织不一致";
                return false;
            }
            if (Customer.Site != profile.SiteId)
            {
                message = "当前登录的组织与档案所在组织不一致";
                return false;
            }
            if (profile.SpCtl && Customer.SalesPointId != profile.SalesPoint)
            {
                message = "当前登录的门店与档案所在门店不一致";
                return false;
            }
            bool result = CustomerUpdater.Remove(Customer, tran, fetcher, out message);
            return result;
        }

        public override bool DeleteById( long[] CustomerIds, out string message)
        {
            bool result = true;
            result = CustomerUpdater.RemoveById( profile.SiteId, CustomerIds, tran, fetcher, out message);
            return result;
        }

        public override bool Save( CustomerModel Customer,  out string message, params IAddable<CustomerModel>[] addables)
        {

            if (Customer.Site != profile.SiteId)
            {
                message = "当前登录的组织与档案所在组织不一致";
                return false;
            }
            if (profile.SpCtl && Customer.SalesPointId != profile.SalesPoint)
            {
                message = "当前登录的门店与档案所在门店不一致";
                return false;
            }
            bool result = true;
            result = CustomerUpdater.Save( Customer, tran, fetcher, out message);
            return result;
        }
    }
}
